package badge

import (
	"gddgame.cc/galaxy/common/dsl/game"
	"gddgame.cc/galaxy/utils"
)

//go:generate msgp

//msgp:tuple UserBadge
type UserBadge struct {
	Id    int    `json:"id" msg:"id"`
	Level int    `json:"level" msg:"level"`
	Date  string `json:"date" msg:"date"`
	Goal  int    `json:"goal" msg:"goal"`
}

//msgp:tuple Badge
type Badge struct {
	Id    int    `json:"id" msg:"id"`
	Name  string `json:"name" msg:"name"`
	Desc  string `json:"desc" msg:"desc"`
	Icon  string `json:"icon" msg:"icon"`
	Way   string `json:"way" msg:"way"`
	Score int    `json:"score" msg:"score"`
	Goal  int    `json:"goal" msg:"goal"`

	Children []*Badge `json:"children" msg:"children"`
	Type     int      `json:"type" msg:"type"`

	Extend interface{} `json:"extend" msg:"extend"`

	*game.DataExtend `json:"-" msg:"-"`
}

func NewBadge(provider *game.DataProvider, badge *SettingBadge) *Badge {
	extend := game.NewDataExtend(utils.ToString(badge.Id), badge.UpdateTime).Add("name", badge.Name).Add("desc", badge.Desc).Add("way", badge.Way)
	ext := &Badge{
		Id:       badge.Id,
		Name:     provider.LanguageKey(extend.Inline(), "name"),
		Desc:     provider.LanguageKey(extend.Inline(), "desc"),
		Icon:     badge.Icon,
		Way:      provider.LanguageKey(extend.Inline(), "way"),
		Score:    badge.Score,
		Goal:     int(badge.GetGoal()),
		Children: []*Badge{},
		Type:     badge.Type,

		Extend: badge.Extend,

		DataExtend: extend,
	}
	return ext
}
